package com.shop;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 王瑞文
 * Date: 2020/9/6
 * Time: 16:44
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@EnableZuulProxy
@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
@RefreshScope
public class GetWay {
    public static void main(String[] args) {
        SpringApplication.run(GetWay.class,args);
    }
    // 添加文档来源
    @Component
    @Primary
    class DocumentationConfig implements SwaggerResourcesProvider {
        @Override
        public List<SwaggerResource> get() {
            List resources = new ArrayList<>();
            // app-itmayiedu-order
            //网关使用别名获取远程服务的swaggerAPI
            resources.add(swaggerResource("OSS图片上传服务", "/shop-impl-oss/v2/api-docs", "2.0"));
            resources.add(swaggerResource("SMS短信发送服务", "/shop-impl-sms/v2/api-docs", "2.0"));
            resources.add(swaggerResource("商品管理服务", "/shop-impl-goods/v2/api-docs", "2.0"));
            resources.add(swaggerResource("人员管理服务", "/shop-impl-member/v2/api-docs", "2.0"));
            return resources;
        }

        private SwaggerResource swaggerResource(String name, String location, String version) {
            SwaggerResource swaggerResource = new SwaggerResource();
            swaggerResource.setName(name);
            swaggerResource.setLocation(location);
            swaggerResource.setSwaggerVersion(version);
            return swaggerResource;
        }

    }
}
